package com.transitionseverywhere.utils;

import android.animation.LayoutTransition;
import android.os.Build;
import android.view.ViewGroup;
import com.transitionseverywhere.R;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/* loaded from: classes.dex */
public class ViewGroupUtils {
    private static final BaseViewGroupUtils IMPL;

    /* loaded from: classes.dex */
    static class BaseViewGroupUtils {
        private static final Method METHOD_LAYOUT_TRANSITION_CANCEL = ReflectionUtils.getPrivateMethod(LayoutTransition.class, "cancel", new Class[0]);
        private static LayoutTransition sEmptyLayoutTransition;
        private static Field sFieldLayoutSuppressed;

        BaseViewGroupUtils() {
        }

        public void suppressLayout(final ViewGroup viewGroup, boolean z) {
            if (sEmptyLayoutTransition == null) {
                sEmptyLayoutTransition = new LayoutTransition() { // from class: com.transitionseverywhere.utils.ViewGroupUtils.BaseViewGroupUtils.1
                    @Override // android.animation.LayoutTransition
                    public boolean isChangingLayout() {
                        return true;
                    }
                };
                sEmptyLayoutTransition.setAnimator(2, null);
                sEmptyLayoutTransition.setAnimator(0, null);
                sEmptyLayoutTransition.setAnimator(1, null);
                sEmptyLayoutTransition.setAnimator(3, null);
                sEmptyLayoutTransition.setAnimator(4, null);
            }
            if (z) {
                cancelLayoutTransition(viewGroup);
                LayoutTransition layoutTransition = viewGroup.getLayoutTransition();
                if (layoutTransition != null && layoutTransition != sEmptyLayoutTransition) {
                    viewGroup.setTag(R.id.group_layouttransition_backup, viewGroup.getLayoutTransition());
                }
                viewGroup.setLayoutTransition(sEmptyLayoutTransition);
                return;
            }
            viewGroup.setLayoutTransition(null);
            if (sFieldLayoutSuppressed == null) {
                sFieldLayoutSuppressed = ReflectionUtils.getPrivateField(ViewGroup.class, "mLayoutSuppressed");
            }
            if (!Boolean.FALSE.equals((Boolean) ReflectionUtils.getFieldValue(viewGroup, Boolean.FALSE, sFieldLayoutSuppressed))) {
                ReflectionUtils.setFieldValue(viewGroup, sFieldLayoutSuppressed, false);
                viewGroup.requestLayout();
            }
            final LayoutTransition layoutTransition2 = (LayoutTransition) viewGroup.getTag(R.id.group_layouttransition_backup);
            if (layoutTransition2 != null) {
                viewGroup.setTag(R.id.group_layouttransition_backup, null);
                viewGroup.post(new Runnable() { // from class: com.transitionseverywhere.utils.ViewGroupUtils.BaseViewGroupUtils.2
                    @Override // java.lang.Runnable
                    public void run() {
                        viewGroup.setLayoutTransition(layoutTransition2);
                    }
                });
            }
        }

        public boolean cancelLayoutTransition(ViewGroup viewGroup) {
            LayoutTransition layoutTransition;
            if (viewGroup == null || (layoutTransition = viewGroup.getLayoutTransition()) == null || !layoutTransition.isRunning() || METHOD_LAYOUT_TRANSITION_CANCEL == null) {
                return false;
            }
            ReflectionUtils.invoke(viewGroup.getLayoutTransition(), null, METHOD_LAYOUT_TRANSITION_CANCEL);
            return true;
        }
    }

    /* loaded from: classes.dex */
    static class JellyBeanMr2ViewGroupUtils extends BaseViewGroupUtils {
        private static final Method METHOD_suppressLayout = ReflectionUtils.getMethod(ViewGroup.class, "suppressLayout", Boolean.TYPE);

        JellyBeanMr2ViewGroupUtils() {
        }

        @Override // com.transitionseverywhere.utils.ViewGroupUtils.BaseViewGroupUtils
        public void suppressLayout(ViewGroup viewGroup, boolean z) {
            ReflectionUtils.invoke(viewGroup, (Object) null, METHOD_suppressLayout, Boolean.valueOf(z));
        }
    }

    static {
        if (Build.VERSION.SDK_INT >= 18) {
            IMPL = new JellyBeanMr2ViewGroupUtils();
        } else {
            IMPL = new BaseViewGroupUtils();
        }
    }

    public static void suppressLayout(ViewGroup viewGroup, boolean z) {
        if (viewGroup != null) {
            IMPL.suppressLayout(viewGroup, z);
        }
    }

    public static boolean cancelLayoutTransition(ViewGroup viewGroup) {
        return IMPL.cancelLayoutTransition(viewGroup);
    }
}
